package shellstation;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;

public class SalesReportView implements ActionListener{
private JTable SalesReport;

    private JLabel salesReportText;

    private JPanel redBox;

    private JLabel from;
    private JLabel to;

    private JScrollPane scrollpane;

    private JButton find;

    private JTextField year;
    private JTextField year2;

    private JComboBox month;
    private JComboBox day;
    private JComboBox month2;
    private JComboBox day2;

    private Color red = new Color(226, 0, 0);
    private Color gray = new Color(182, 182, 182);

    private Integer[] monthNum = new Integer[13];
    private Integer[] dayNum = new Integer[32];

    private String[] columnName = {"Product Name", "Sold", "Price"};
    private Object[][] rowData = {
                                    {"Advance 2T", new Integer(5), new Integer(28)},
                                    {"Helix HX5", new Integer(10), new Integer(228)},
                                    {"Rimula R3 X", new Integer(3), new Integer(197)}
                                 };
    public void SalesReportView(){

        salesReportText = new JLabel("Sales Report");
        salesReportText.setBounds(90, 0, 250, 100);
        salesReportText.setFont(new Font("Hobo Std", Font.BOLD, 28));

        from = new JLabel("From:");
        from.setBounds(30, 105, 70, 30);
        from.setFont(new Font("Arial", Font.BOLD, 20));

        to = new JLabel("To:");
        to.setBounds(230, 105, 70, 30);
        to.setFont(new Font("Arial", Font.BOLD, 20));

        redBox= new JPanel(null);
        redBox.setBackground(red);
        redBox.setBounds(0,0, 550, 10);

        for(int i=0; i<31; i++){
            dayNum[i]= i+1;

            if(i<12)
            monthNum[i] = i+1;
        }

        month= new JComboBox(monthNum);
        month.setBounds(35, 140, 50, 20);

        day= new JComboBox(dayNum);
        day.setBounds(100, 140, 50, 20);

        month2= new JComboBox(monthNum);
        month2.setBounds(250, 140, 50, 20);

        day2= new JComboBox(dayNum);
        day2.setBounds(315, 140, 50, 20);

        year= new JTextField("Year",4);
        year.setBounds(165, 140, 50, 20);

        year2= new JTextField("Year",4);
        year2.setBounds(380, 140, 50, 20);

        SalesReport= new JTable(rowData, columnName);
        SalesReport.setFont(new Font("Arial", Font.BOLD, 20));


        scrollpane = new JScrollPane(SalesReport);
        scrollpane.setBounds(23, 220, 400, 100);
        SalesReport.setFillsViewportHeight(true);

        find= new JButton("Find");
        find.setBounds(340, 380, 90,30);
        find.setBackground(gray);
        find.addActionListener(this);
    }

    public JLabel getFrom(){
        return from;
    }

    public JLabel getTo(){
        return to;
    }

    public JPanel getredBox(){
        return redBox;
    }

    public JScrollPane getscrollPane(){
        return scrollpane;
    }

    public JTable getsalesReport(){
        return SalesReport;
    }

    public JComboBox getmonth(){
        return month;
    }

    public JComboBox getday(){
        return day;
    }

    public JTextField getyear(){
        return year;
    }

    public JComboBox getmonth2(){
        return month2;
    }

    public JComboBox getday2(){
        return day2;
    }

    public JTextField getyear2(){
        return year2;
    }

    public JLabel getsalesReportText(){
        return salesReportText;
    }

    public JButton getFind(){
        return find;
    }

    public void actionPerformed(ActionEvent e){

        if(e.getSource() == find){

            String s= year.getText();
            String s2= year2.getText();
            int i;
            int i2;

             while(true){
                try{
                    i= Integer.parseInt(s);
                    i2= Integer.parseInt(s2);

                    if(i <2011 || i2 < 2011){
                        JOptionPane.showMessageDialog(null, "Year should be greater than or equal to 2011");

                    }

                    else if(i >= i2){
                        JOptionPane.showMessageDialog(null, "Year found in TO"+"\n"+ "should be greater than or equal to"+"\n"+
                                                      "the year in FROM ");


                    }

                    break;
                }

                catch(NumberFormatException nx){
                     JOptionPane.showMessageDialog(null, "Year should be a whole number");
                     break;
                }

            }


        }

    }

}
